package My;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Card{
    private String suit;
    private String rank;

    public Card(String suit, String rank) {
        this.suit = suit;
        this.rank = rank;
    }

    public String getSuit() {
        return suit;
    }

    public void setSuit(String suit) {
        this.suit = suit;
    }

    public String getRank() {
        return rank;
    }

    public void setRank(String rank) {
        this.rank = rank;
    }

    @Override
    public String toString() {
        return "Card{" +
                "suit='" + suit + '\'' +
                ", rank='" + rank + '\'' +
                '}';
    }
}
public class Demo01 {
    public static void main(String[] args) {
        ArrayList<Card> deck = createDeck();
        System.out.println("打乱前：");
        System.out.println(deck);
        shuffle(deck);
        System.out.println("打乱后：");
        System.out.println(deck);

        ArrayList<ArrayList<Card>> hands = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            ArrayList<Card> hand = new ArrayList<>();
            hands.add(hand);
        }
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                ArrayList<Card> currentHand = hands.get(j);
                Card card = deck.remove(0);
                currentHand.add(card);
            }
        }
        for (int i = 0; i < 3; i++) {
            System.out.println("第"+i+1+"个人的手牌："+hands.get(i));
        }

    }

    public static void shuffle(ArrayList<Card> deck) {
        Random random = new Random();
        for (int i = deck.size()-1; i >0 ; i--) {
            int j = random.nextInt(deck.size());
            Card temp = new Card(deck.get(i).getSuit(),deck.get(i).getRank());
            deck.set(i,deck.get(j));
            deck.set(j,temp);
        }
    }
    public static ArrayList<Card> createDeck(){
        ArrayList<Card> deck= new ArrayList<>();
        String[] suits = {"♠", "♥", "♦", "♣"};
        for(String suit : suits) {
            for (int i = 2; i <= 10; i++) {
                Card card = new Card(suit,""+ i);
                deck.add(card);
            }
            Card cardJ = new Card(suit,"J");
            Card cardQ = new Card(suit,"Q");
            Card cardK = new Card(suit,"K");
            Card cardA = new Card(suit,"A");
            deck.add(cardJ);
            deck.add(cardQ);
            deck.add(cardK);
            deck.add(cardA);

        }
        return deck;
    }
}
